package com.greenold.residing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.greenold.residing.domain.RoomType;
import com.greenold.residing.domain.RoomTypeStatusDTO;
import com.greenold.residing.service.IRoomTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.greenold.common.annotation.Log;
import com.greenold.common.core.controller.BaseController;
import com.greenold.common.core.domain.AjaxResult;
import com.greenold.common.enums.BusinessType;
import com.greenold.common.utils.poi.ExcelUtil;
import com.greenold.common.core.page.TableDataInfo;

/**
 * 房型设置Controller
 * 
 * @author ruoyi
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/residing/roomType")
public class RoomTypeController extends BaseController
{
    @Autowired
    private IRoomTypeService roomTypeService;

    /**
     * 查询房型设置列表
     */
    @PreAuthorize("@ss.hasPermi('residing:roomType:list')")
    @GetMapping("/list")
    public TableDataInfo list(RoomType roomType)
    {
        startPage();
        List<RoomType> list = roomTypeService.selectRoomTypeList(roomType);
        return getDataTable(list);
    }

    /**
     * 查询启用房型列表
     */
    @GetMapping("/listEnabled")
    public TableDataInfo listEnabled(RoomType roomType)
    {
        startPage();
        List<RoomType> list = roomTypeService.selectRoomTypeListEnabled(roomType);
        return getDataTable(list);
    }

    /**
     * 导出房型设置列表
     */
    @PreAuthorize("@ss.hasPermi('residing:roomType:export')")
    @Log(title = "房型设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RoomType roomType)
    {
        List<RoomType> list = roomTypeService.selectRoomTypeList(roomType);
        ExcelUtil<RoomType> util = new ExcelUtil<RoomType>(RoomType.class);
        util.exportExcel(response, list, "房型设置数据");
    }

    /**
     * 获取房型设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('residing:roomType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(roomTypeService.selectRoomTypeById(id));
    }

    /**
     * 新增房型设置
     */
    @PreAuthorize("@ss.hasPermi('residing:roomType:add')")
    @Log(title = "房型设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RoomType roomType)
    {
        return toAjax(roomTypeService.insertRoomType(roomType));
    }

    /**
     * 修改房型设置
     */
    @PreAuthorize("@ss.hasPermi('residing:roomType:edit')")
    @Log(title = "房型设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RoomType roomType)
    {
        return toAjax(roomTypeService.updateRoomType(roomType));
    }

    /**
     * 修改房型状态
     */
    @PreAuthorize("@ss.hasPermi('residing:roomType:edit')")
    @Log(title = "状态修改", businessType = BusinessType.UPDATE)
    @PutMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody RoomTypeStatusDTO dto)
    {
        return toAjax(roomTypeService.updateRoomStatus(dto));
    }

    /**
     * 删除房型设置
     */
    @PreAuthorize("@ss.hasPermi('residing:roomType:remove')")
    @Log(title = "房型设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(roomTypeService.deleteRoomTypeByIds(ids));
    }
}
